package com.icez.base_compose_framework.util

import androidx.window.core.layout.WindowHeightSizeClass
import androidx.window.core.layout.WindowSizeClass
import androidx.window.core.layout.WindowWidthSizeClass
import androidx.window.layout.FoldingFeature
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract


object BWindowInfoUtil {

    /**
     * 判断是否为平板
     * @param foldFeature 折叠屏幕信息
     */
    @OptIn(ExperimentalContracts::class)
    public fun isTableTopPosture(foldFeature:FoldingFeature?):Boolean{
        //函数返回 true，那么 foldFeature 必须不为 null
        contract {returns(true) implies (foldFeature != null)}
        //折叠特征处于半打开状态 && 折叠特征的方向为水平
        return foldFeature?.state == FoldingFeature.State.HALF_OPENED && foldFeature.orientation == FoldingFeature.Orientation.HORIZONTAL
    }

    /**
     * 判断是否为Book
     * @param foldFeature 折叠屏幕信息
     */
    @OptIn(ExperimentalContracts::class)
    public fun isBookPosture(foldFeature:FoldingFeature?):Boolean{
        //函数返回 true，那么 foldFeature 必须不为 null
        contract { returns(true) implies (foldFeature != null) }
        // 折叠特征处于半打开状态 && 折叠特征的方向为垂直
        return foldFeature?.state == FoldingFeature.State.HALF_OPENED && foldFeature.orientation == FoldingFeature.Orientation.VERTICAL
    }

    /**
     * 判断是否为分离状态
     * @param foldFeature 折叠屏幕信息
     */
    @OptIn(ExperimentalContracts::class)
    public fun isSeparatingPosture(foldFeature: FoldingFeature?):Boolean{
        //函数返回 true，那么 foldFeature 必须不为 null
        contract { returns(true) implies (foldFeature != null) }
        // 折叠特征处于平坦状态 && 折叠特征处于分离状态
        return foldFeature?.state == FoldingFeature.State.FLAT && foldFeature.isSeparating
    }

    /**
     * 判断是否为紧凑型
     * @param windowSizeClass 窗口尺寸信息
     */
    fun isCompact(windowSizeClass: WindowSizeClass):Boolean {
        return windowSizeClass.windowWidthSizeClass == WindowWidthSizeClass.COMPACT ||
                windowSizeClass.windowHeightSizeClass == WindowHeightSizeClass.COMPACT
    }
}